//
//  SurePayViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/24.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "SurePayViewController.h"
#import "JTCSM.h"
#import "MyInfoView.h"
static CGFloat space = 20;
@interface SurePayViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
{
    UIScrollView *backScrollV;
    UILabel *mylabel;
    NSString *code;
}
@property (nonatomic,strong) UITextField *textfield;
@end

@implementation SurePayViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight-50)];
    backScrollV.backgroundColor = [UIColor whiteColor];
    backScrollV.userInteractionEnabled = YES;
    backScrollV.bounces = NO;
    backScrollV.showsVerticalScrollIndicator = NO;
    [self.view addSubview:backScrollV];
    [self layoutOtherView];
}

- (void)layoutOtherView{
    
    CGFloat changeHeight = 15;
    
    UILabel *choiceLabel = [UILabel initWithFrame:CGRectMake(space, 30, KCONTROLLERWith-2*space, 20) text:@"支付金额" font:20 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:nil];
    [backScrollV addSubview:choiceLabel];
    CGFloat LabelHeight = 50;
    NSString *title = @"¥";
    CGFloat font = 40;
    CGRect rect = [df labelHeightWithContent:title height:LabelHeight font:font];
    
    UILabel *label = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(choiceLabel)+changeHeight, rect.size.width, LabelHeight) text:title font:font textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
    [backScrollV addSubview:label];
    
    
    self.textfield = [UITextField initWithframe:CGRectMake(KVIEW_X(label), KVIEW_Y(choiceLabel)+changeHeight+5, KCONTROLLERWith-KVIEW_X(label)-space, LabelHeight) backgrandColor:nil placeholder:@"输入金额" textAlignment:NSTextAlignmentLeft font:20 texcolor:RGBACOLOR(89, 89, 89, 1)];
    self.textfield.text = _money;
    self.textfield.enabled = NO;
    [backScrollV addSubview:self.textfield];
    
    [df lineViewWithHeightofTop:KVIEW_Y(self.textfield)+10 superView:backScrollV spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:2];
    
    
    mylabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(_textfield)+10, KCONTROLLERWith, 40) text:@"     银行卡信息" font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:RGBACOLOR(241, 241, 241, 1)];
    [backScrollV addSubview:mylabel];
    
    NSArray *textArr = @[@"银行卡信息",@"银行卡号",@"手机号",@"验证码"];
    NSArray *contentArr = @[_bankname,_bankcard,_banktel];
    CGFloat theViewHeight = (KSCREENWidth ==320)?30:40;
    MyInfoView *theView;
    for (int i = 0 ; i < textArr.count; i++) {
        theView = [[MyInfoView alloc]initWithFrame:CGRectMake(space, KVIEW_Y(mylabel)+(theViewHeight*i), KCONTROLLERWith-2*space, theViewHeight) imagename:nil title:textArr[i] placeholder:nil isShowLabel:RightlabelType radioBtnIndex:0 GroupId:nil];
        theView.textfield.delegate = self;
        theView.label.font = [UIFont systemFontOfSize:16];
        theView.tag = 1000+i;
        if (i == textArr.count-1) {
            theView.textfield.placeholder = @"请输入验证码";
            theView.textfield.delegate = self;
            [theView.textfield addTarget:self  action:@selector(valueChanged:)  forControlEvents:UIControlEventAllEditingEvents];
        }else{
            theView.textfield.enabled = NO;
            theView.textfield.text = contentArr[i];
        }

        [backScrollV addSubview:theView];
        
        
    }
    CGFloat btnspace = 20;
    CGFloat btnHeight = 50;
    UIButton *LoginBtn =[[UIButton alloc] initWithFrame:CGRectMake(btnspace, KVIEW_Y(theView)+20 , (KCONTROLLERWith-2*btnspace), btnHeight)];
    LoginBtn.backgroundColor =RGBACOLOR(227, 68, 40, 1);
    [LoginBtn setTitle:@"确认支付" forState:UIControlStateNormal];
    [LoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //[df layerWithView:LoginBtn radius:4 width:2 color:RGBACOLOR(172,134,171, 1)];
    [LoginBtn addTarget:self action:@selector(gotoMainV) forControlEvents:UIControlEventTouchUpInside];
    LoginBtn.tag = 10002;
    [backScrollV addSubview:LoginBtn];
    [df layerWithView:LoginBtn radius:btnHeight/2 width:0 color:nil];
    
}

- (void)valueChanged:(UITextField *)textfield{
    code = textfield.text;
}

- (void)gotoMainV{
//    UserExpense/confirm
//    "code":"2","client_num":3
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserExpense/confirm") withDict:@{@"token":KTokenString,@"code":code==nil?@"":code,@"client_num":self.client_num} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
//            if ([[KResultOfKey(@"data") objectForKey:@"source"] isEqualToString:@""] ||[KResultOfKey(@"data") objectForKey:@"source"]==nil) {
//              
//            }else{
//                
//                self.client_num = [KResultOfKey(@"data") objectForKey:@"source"];
//                WebViewController *vc = [[WebViewController alloc]init];
//                vc.titleName = @"王者管家";
//                vc.urlStr = [KResultOfKey(@"data") objectForKey:@"source"];
//                [self.navigationController pushViewController:vc animated:YES];
//            }
            
              [df showAlertWithTitle:KResultOfKey(@"msg") message:nil btn1:@"好的" btn2:nil btn3:nil delegate:self tag:123];
            
        }else{
            [df showAlertWithTitle:KResultOfKey(@"msg") message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
        }
    }];

    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == KAlertVTag+123) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    MyInfoView *theView = [backScrollV viewWithTag:1003];
    [theView.textfield resignFirstResponder];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
